package com.design.pattern.principle.dependencyInversion.improve.dependCase3;

public class DependCase3 {
    public static void main(String[] args) {
        //通过setter方法进行依赖传递
        OpenAndClose openAndClose = new OpenAndClose();
        openAndClose.setTv(new ChangHong());
        openAndClose.open();
    }
}

class ChangHong implements ITV {

    @Override
    public void play() {
        System.out.println("长虹电视机。打开");
    }
}

/**
 * 通过setter方法传递
 */
interface IOpenAndClose {
    void open();

    void setTv(ITV tv);
}

interface ITV {
    void play();
}

class OpenAndClose implements IOpenAndClose {
    private ITV tv;

    @Override
    public void open() {
        this.tv.play();
    }

    @Override
    public void setTv(ITV tv) {
        this.tv = tv;
    }
}
